/**
 * Created by Administrator on 2020/5/14.
 */
;
//创建数据库连接
var mysql = require("mysql");
exports.mysqlClient = function (table) {

    this.db = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "xuyanzhao",
        database: "product"
    });
    this.db.connect();
    this.insertData = function (data) {
        STRING = "";
        VALUES = "";
        for (var key in data) {
            STRING += "`" + key + "`" + ",";
            VALUES += '"' + data[key] + '"' + ",";
        }
        fields = ( STRING.substring(0, STRING.length - 1));
        values = ( VALUES.substring(0, VALUES.length - 1));
        Sql = 'INSERT INTO `' + table + '`(' + fields + ')VALUES(' + values + ')';
        this.db.query(Sql, function (err, result) {
            if (err) {
                console.log(err);
                return;
            }
        });
        console.log(Sql);



    };
    this.close = function () {
        this.db.end();
    }
};

